package com.ruoyi.project.student.service.impl;

import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
import com.ruoyi.project.student.domain.Student;
import com.ruoyi.project.student.domain.param.StudentListParam;
import com.ruoyi.project.student.domain.vo.StudentListVo;
import com.ruoyi.project.student.mapper.StudentMapper;
import com.ruoyi.project.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServicelmpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 根据条件分页查询学生列表
     *
     * @param param 学生信息
     * @return 学生信息集合信息
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<StudentListVo> selectStudentList(StudentListParam param)
    {
        return  studentMapper.selectStudentList(param);
    }

    @Override
    public List<Student> insertStudentList(Student student) {
        return null;
    }

    @Override
    public int insertStudent(Student student) throws Exception{
        if (student.getNumber() == null || student.getNumber().equals("")){
            throw new Exception("学号不能为空");
        }
        if (student.getName() == null || student.getName().equals("")){
            throw new Exception("姓名不能为空");
        }
        int i = studentMapper.insertStudent(student);
        return i;
    }
    @Override
    public Student edit(Student student) throws Exception {
        Student target= studentMapper.selectById(student.getId());
        target.setName(student.getName());
        target.setNumber(student.getNumber());
        studentMapper.editStudentById(target);
        return target;
    }


    @Override
    public int delete(Student student) throws Exception {
        return studentMapper.delStudent(student.getId());
    }
}
